/*
 * 功能:黛米安(简单)事件
 * Form: 芬芬时尚潮流
 */

//自定义复活次数
var nDeathCount = 5;

function init() {
	em.setProperty("state", "0");
	em.setProperty("leader", "true");
}
/*
 * 地图ID
 * 350160200 - 堕落世界树 - 世界树顶端
 * 350160240 - 堕落世界树 - 世界树顶端
 *
 * 怪物
 * 8880110 - 戴米安 一阶段
 * 8880111 - 戴米安 二阶段
 *
 */
function setup(level, partyid) {
	em.setProperty("state", "1");
	em.setProperty("leader", "true");
	var eim = em.newInstance("BossDemian_NORMAL");
	var map1 = eim.setInstanceMap(350160200);
	var map2 = eim.setInstanceMap(350160240);
	map1.resetFully();
	map2.resetFully();
	eim.setProperty("summom", "0");
	eim.startEventTimer(30 * 60 * 1000);
	return eim;
}

function playerEntry(eim, player) {
	var map = eim.getMapInstance(0);
	player.setReviveCount(nDeathCount);
	player.changeMap(map, map.getPortal(0));
}

function changedMap(eim, player, mapid) {
	if (mapid != 350160200 && mapid != 350160240) {
		eim.unregisterPlayer(player);
		if (eim.disposeIfPlayerBelow(0, 0)) {
			em.setProperty("state", "0");
			em.setProperty("leader", "true");
		}
	}
}

function playerDisconnected(eim, player) {
	return 0;
}

function scheduledTimeout(eim) {
	eim.disposeIfPlayerBelow(100, 105300303);
	em.setProperty("state", "0");
	em.setProperty("leader", "true");
}

function playerExit(eim, player) {
	eim.unregisterPlayer(player);
	if (eim.disposeIfPlayerBelow(0, 0)) {
		em.setProperty("state", "0");
		em.setProperty("leader", "true");
	}
}

function monsterValue(eim, mobId) {
	return 1;
}

function allMonstersDead(eim) {
	var state = em.getProperty("state");
	if (state.equals("1")) {
		em.setProperty("state", "2");
		eim.schedule("warpNext", 2700);
	} else if (state.equals("2")) {
		em.setProperty("state", "3");
		//eim.schedule("warpNext", 4700);
	} else {
		eim.setProperty("stop", "1");
	}
}

function playerRevive(eim, player) {
	if (player.getReviveCount() > 0) {
		var map = player.getMap();
		player.eventRevive(map, map.getPortal(0));
		return true;
	}
	player.addHP(50);
	var map = eim.getMapFactoryMap(105300303);
	player.changeMap(map, map.getPortal(0));
	return true;
}

function clearPQ(eim) {
	scheduledTimeout(eim);
}
function leftParty(eim, player) {}
function disbandParty(eim) {}
function playerDead(eim, player) {}
function cancelSchedule() {}
function warpNext(eim) {
	var map;
	var state = parseInt(em.getProperty("state"));
	for (var i = 0; i < eim.getPlayers().size(); i++) {
		map = eim.getMapInstance(state - 1);
		eim.getPlayers().get(i).changeMap(map, map.getPortal(0));
	}
}

function pickUpItem(eim, player, itemID) {}
function monsterDamaged(eim, player, mobID, damage) {}
function monsterKilled(eim, player, mobID) {}
